import axios from "axios";

/**
 * 发送聊天请求到千帆API
 * @param {string} endpoint API端点
 * @param {Object} params 请求参数
 * @returns {Promise<Object>} API响应
 */
export async function sendChatRequest(model, message) {
  console.log("params", model);
  console.log("endpoint", JSON.stringify(message));
  const requestData = {
    model: model,
    messages: [{ role: "user", content: JSON.stringify(message) }],
    temperature: 0.7,
    top_p: 0.8,
    penalty_score: 1,
    enable_thinking: false,
  };
  console.log("endpoint", requestData);
  try {
    const response = await axios.post(
      "https://qianfan.baidubce.com/v2/chat/completions",
      requestData,
      {
        headers: {
          "Content-Type": "application/json",
          // ! 此处的API Key需要替换成实际API Key,测试API Key已取消访问权限
          Authorization: `Bearer ${YOUR_API_KEY}`,
        },
      }
    );
    return response.data;
  } catch (error) {
    console.error("千帆API请求失败:", error.response?.data || error.message);
    throw error;
  }
}
